package com.logic.landseaserver.service.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.logic.landseaserver.common.util.DESUtil;
import com.logic.landseaserver.domain.WeChatUserLogin;
import com.logic.landseaserver.persistence.read.WeChatUserLoginReadMapper;
import com.logic.landseaserver.service.IWeChatLoginService;
import com.logic.system.service.IWeChatService;

import net.sf.json.JSONObject;


@Service
public class WeChatLoginServiceImpl implements IWeChatLoginService {

	@Autowired
	IWeChatService weChatService;
	@Autowired
	WeChatUserLoginReadMapper weChatUserLoginReadMapper;
	
	private static Logger logger = LoggerFactory.getLogger(WeChatLoginServiceImpl.class);
	
	@Override
	public WeChatUserLogin loginByCode(String code) throws Exception {
		
		String userinfo = weChatService.getUserInfoByCode(code);
		logger.info("微信登陆端userId: "+userinfo);
		JSONObject userjson = JSONObject.fromObject(userinfo);
		String username = userjson.getString("UserId");
		WeChatUserLogin loginInfo = weChatUserLoginReadMapper.selectByUsername(username);
		loginInfo.setPassword(DESUtil.decrypt(loginInfo.getPassword()));
		return loginInfo;
	}

	@Override
	public String getCorporate() throws Exception {
		String list = weChatService.getCorperateList();
		return list;
	}
}